<?php 
include 'include/functions.php';
require_once 'include/ImageManipulator.php';

$text = $_POST["text"];
$finalWidth = "150";

if (!empty($_FILES)){
	
	$filename = openssl_random_pseudo_bytes(8) . '.jpg';
	$file_src = 'pictures/'.$filename;
	
	$manipulator = new ImageManipulator($_FILES['file']['tmp_name']);

	$currentWidth = $manipulator->getWidth();
	$currentHeight = $manipulator->getHeight();
	
	
	$ratio = ($finalWidth * 100) / $currentWidth;
	$imageWitdh = $finalWidth;
	$imageHeight = ($ratio * $currentHeight) / 100;
	
	$newImage = $manipulator->resample($imageWitdh, $imageHeight);
	$manipulator->save($file_src);
		
	$filePath = "http://37.187.34.116:81/MustDo/" . $file_src;
	saveMustDo($text, $filePath, 1);//1 means Active. In production change for 0.
	
	$message = 'Your file has been uploaded sucessfully';
	
} else{
	$message = "no file";
}

$data = array('MustDo' => $arrMustDo, 'status' => "ok", 'message' => $message, 'fileURL' => "");
$json = json_encode($data);
echo $json;
?>